package com.hualan.dao.impl;


import com.hualan.bean.PanghuDeliveryOrder;
import com.hualan.dao.PanghuDeliveryOrderDao;
import com.hualan.utils.C3p0Util;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class PanghuDeliveryOrderDaoImpl implements PanghuDeliveryOrderDao {
    @Override
    public List<PanghuDeliveryOrder> getPanghuDeliveryOrder(int deliveryOrderType,int orderStatus, String deliveryUserPhone, String deliveryUserName, Date orderCreateTime, Date orderCompleteTime, int page, int size) {
        //配送订单类型,订单状态,页码,每页条数,不会为空
        //收货人手机号,收货联系人,订单创建时间,订单完成时间可以为空

        String deliveryOrderStatus="";
        if (orderStatus!=0){
            deliveryOrderStatus=orderStatus+"";
        }
        System.out.println(deliveryUserName);

        String sqlString = "select delivery_order_id,delivery_order_type,delivery_order_status,delivery_order_create_time,pickup_address,pickup_address_detail,delivery_address,delivery_address_detail,pickup_user_name,pickup_user_phone,delivery_user_phone,delivery_user_name,order_note,order_buy_goods_note,delivery_order_receive_time,delivery_order_complete_time,delivery_man_id,delivery_man_name,user_id,order_number,user_unionid,user_applet_openid,purchase_shop_id,goods_type,goods_value,courier_info_image,goods_weight,courier_station_id,courier_station_community_id from panghu_delivery_order where delivery_order_type = ? and delivery_order_status like '"+deliveryOrderStatus+"%' and delivery_user_phone like " + "'%" + deliveryUserPhone + "%' " + " and delivery_user_name like " + "'%" + deliveryUserName + "%' " + " and delivery_order_create_time >= ? and delivery_order_create_time <= ? limit ?,?";

        List<PanghuDeliveryOrder> list = C3p0Util.query(sqlString, PanghuDeliveryOrder.class, deliveryOrderType,  orderCreateTime, orderCompleteTime, (page - 1) * size, size);

        return list;
    }

    @Override
    public Long selectAllPanghuDeliveryOrderCount(int deliveryOrderType,int orderStatus, String deliveryUserPhone, String deliveryUserName, Date orderCreateTime, Date orderCompleteTime) {
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String deliveryOrderStatus="";
        if (orderStatus!=0){
            deliveryOrderStatus=orderStatus+"";
        }


        String sqlString = "select count(*) as count from panghu_delivery_order where delivery_order_type = ? and  delivery_order_status like '"+ deliveryOrderStatus+ "%'and  delivery_user_phone like " + "'%" + deliveryUserPhone + "%' " + " and delivery_user_name like " + "'%" + deliveryUserName + "%' " + " and delivery_order_create_time >= ? and delivery_order_create_time <= ?";

        Map<String, Object> map = C3p0Util.queryOne(sqlString,deliveryOrderType, orderCreateTime, orderCompleteTime);

        Long count = null;
        if (map != null) {
            count = (Long) map.get("count");
        }
        return count;


    }
}


